/**
 * Holds the score, lives, etc..
 * 
 * created 11-18
 * @author Jonathan Odom, Andrew Cook
 */

package vooga.core;
import vooga.util.*;
import java.io.IOException;

public class Status {
	public enum GameState {INTRO, RUNNING, QUIT, GAME_OVER, WON}
	
	private long myScore;
	private int myLives;
	private int myLevelNumber;
	private GameState myGameState;
	private String myGameName;
	private String myPlayerName;
	private static String DEFAULT_GAME_NAME = "Game";
	private static String DEFAULT_PLAYER_NAME = "Guest";
	private PropertiesManager myProperties;
	
	//Constructors, including reading from a file
	public Status()
	{
		this(0,0);
	}
	
	public Status(int newScore, int newLives)
	{
		this(DEFAULT_PLAYER_NAME, DEFAULT_GAME_NAME, 1, newLives, newScore, GameState.INTRO);
	}
	
	public Status(String filename)
	{
		try
		{
			myProperties = new PropertiesManager(filename);
			myLives = Integer.parseInt(myProperties.getString("lives"));
			myLevelNumber = Integer.parseInt(myProperties.getString("level"));
			myScore = Long.parseLong(myProperties.getString("score"));
			myGameName = myProperties.getString("game");
			myGameState = myGameState.valueOf(myProperties.getString("gamestate"));
			myPlayerName = myProperties.getString("player");
		}
		catch(IOException e)
		{
			System.out.print("Go boom");
		}
	}
	
	public Status(String playerName, String gameName, int level, int lives, long score, GameState state)
	{
		myPlayerName = playerName;
		myGameName = gameName;
		myLevelNumber = level;
		myLives = lives;
		myScore = score;
		myGameState = state;
	}
	
	public Status(String playerName, String gameName)
	{
		this(playerName, gameName, 1, 0, 0, GameState.INTRO);
	}
	
	//Methods: standard get and set, as well as filewriting functionality
	public void addScore(int added)
	{
		myScore += added;
	}
	
	public void addLives(int added)
	{
		myLives += added;
	}

	/**
	 * @return the lives
	 */
	public int getLives() {
		return myLives;
	}

	/**
	 * @param lives the lives to set
	 */
	public void setLives(int lives) {
		myLives = lives;
	}

	/**
	 * @return the score
	 */
	public long getScore() {
		return myScore;
	}

	/**
	 * @param score the score to set
	 */
	public void setScore(long score) {
		myScore = score;
	}

	/**
	 * @return the level
	 */
	public int getLevelNumber() {
		return myLevelNumber;
	}
	
	/**
	 * @param the level to set
	 */
	public void setLevelNumber(int levelNumber) {
		myLevelNumber = levelNumber;
	}

	public void addLevelNumber(int added) {
		myLevelNumber += added;
	}
	
	/**
	 * @return the GameState
	 */
	public GameState getGameState()
	{
		return myGameState;
	}

	public void setGameState(GameState gameState)
	{
		myGameState = gameState;
	}
	
	/**
	 * @return the game name
	 */
	public String getGameName()
	{
		return myGameName;
	}
	
	public void setGameName(String name)
	{
		myGameName = name;
	}
	
	/**
	 * @return the player name
	 */
	public String getPlayerName()
	{
		return myPlayerName;
	}
	
	public void setPlayerName(String newName)
	{
		myPlayerName = newName;
	}
	
	/**
	 * @saves the status to the file
	 */
	public void saveStatus()
	{
		try
		{
			myProperties.setProperty("game", myGameName);
			myProperties.setProperty("lives", new Integer(myLives).toString());
			myProperties.setProperty("level", new Integer(myLevelNumber).toString());
			myProperties.setProperty("score", new Long(myScore).toString());
			myProperties.setProperty("gamestate", myGameState.toString());
			myProperties.setProperty("player", myPlayerName);
		}
		catch(IOException e)
		{
			System.out.println("go boom");
		}
	}
	
	/**
	 * @initializes the status in the properties manager
	 */
	public void initStatus()
	{
		try
		{
			myProperties = new PropertiesManager(myPlayerName + "-" + myGameName);
			myGameState =GameState.INTRO;
		}
		catch(IOException e)
		{
			System.out.println("IO Error");
		}
		saveStatus();
	}
	
}
